package com.practicario.mvc.view
{
    import com.practicario.mvc.ApplicationFacade;
    import com.practicario.mvc.model.vo.TeacherProfileVO;
    import com.practicario.mvc.view.components.PanelProfesor;
    import com.practicario.mvc.view.components.ProfPanelControl;
    
    import flash.events.Event;
    
    import org.puremvc.as3.interfaces.*;
    import org.puremvc.as3.patterns.mediator.Mediator;
    
    public class PanelProfesorMediator extends Mediator implements IMediator
    {
        // Cannonical name of the Mediator
        public static const NAME:String = "PanelProfesorMediator";
        
		public function PanelProfesorMediator( viewComponent:PanelProfesor ) 
        {
            super( NAME, viewComponent );
            app.tmpWindow.addEventListener(ProfPanelControl.UPDATE_PROFILE, onUpdateProfile);                  				
        }   
        
        private function onUpdateProfile(e:Event):void
        {
        	trace('onupdateprofile!');
        	sendNotification(ApplicationFacade.UPDATE_PROFILE, app.tmpWindow.updatePerfilVO);
        }          

        override public function listNotificationInterests():Array 
        {
            return [
						ApplicationFacade.DO_LOG_IN_SUCCESS
					];
        }

        override public function handleNotification( note:INotification ):void 
        {
            switch ( note.getName() ) 
			{
				case ApplicationFacade.DO_LOG_IN_SUCCESS:
				var tmpArray:Array = note.getBody() as Array;
				trace(tmpArray);
				if(tmpArray[0].perfil.profile=="Profesor")
				{
					//se setea el perfil del profesor con los datos que llegan del servicio
					app.menuProfesor.perfil = tmpArray[0].perfil as TeacherProfileVO;					
					app.setCursos(tmpArray[0].careerReceiverVO.career_signatures, tmpArray[0].careerReceiverVO.students);				
				}
				break;
            }
        }

        protected function get app():PanelProfesor
		{
            return viewComponent as PanelProfesor;
        }
    }
}